package singleton;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceSingleton {
    private static AtomicReference<AtomicReferenceSingleton> INSTANCE_HOLDER = new AtomicReference<>();

    private AtomicReferenceSingleton() {
    }

    public static AtomicReferenceSingleton getInstance() {
        for (; ; ) {
            AtomicReferenceSingleton instance = INSTANCE_HOLDER.get();
            if (null != instance) return instance;
            INSTANCE_HOLDER.compareAndSet(null, new AtomicReferenceSingleton());
        }
    }
}
